********************************************************************************
* European elections: do they affect turnout at general elections?
********************************************************************************
* Appendix Table A.3

* Important: only individuals who could vote in estimates

use  "Data_temp/turnout.dta", clear

gen ep1979=ym(1979,6)
gen ep1984=ym(1984,6)
gen ep1989=ym(1989,6)
gen ep1994=ym(1994,6)
gen ep1999=ym(1999,6)
gen ep2004=ym(2004,6)
gen ep2009=ym(2009,6)
gen ep2014=ym(2014,6)

format ep* %tm
	
foreach x in 1979 1984 1989 1994 1999 2004 2009 2014 {
	gen age_ep`x'=(ep`x'-birth_date)-(12*18)
	}
	
	
* edit relative ages at elections relative to European elections	
forvalues x = 0/3 {
	gen age_e`x'=.
	}
replace age_e0=age_ep2014 if election==2017 | election==2015
replace age_e0=age_ep2009 if election==2010
replace age_e0=age_ep2004 if election==2005
replace age_e0=age_ep1999 if election==2001
replace age_e0=age_ep1994 if election==1997
replace age_e0=age_ep1989 if election==1992

replace age_e1=age_ep2009 if election==2017 | election==2015
replace age_e1=age_ep2004 if election==2010
replace age_e1=age_ep1999 if election==2005
replace age_e1=age_ep1994 if election==2001
replace age_e1=age_ep1989 if election==1997
replace age_e1=age_ep1984 if election==1992

replace age_e2=age_ep2004 if election==2017 | election==2015
replace age_e2=age_ep1999 if election==2010
replace age_e2=age_ep1994 if election==2005
replace age_e2=age_ep1989 if election==2001
replace age_e2=age_ep1984 if election==1997
replace age_e2=age_ep1979 if election==1992

replace age_e3=age_ep1999 if election==2017 | election==2015
replace age_e3=age_ep1994 if election==2010
replace age_e3=age_ep1989 if election==2005
replace age_e3=age_ep1984 if election==2001
replace age_e3=age_ep1979 if election==1997


tab election, gen(dummy)
drop dummy1

* pooled estimation
gen rel_age=.
forvalues x = 1/3 {
		replace rel_age=age_e`x' if inrange(age_e`x',-24,24) & rel_age==.
		}

estimates clear	
	
rdrobust voted age_e0 if  england==1 & age0>0 & age_e0!=0, 	p(1) h(24)	covs(dummy*)
	est sto m0
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)

rdrobust voted age_e1 if  england==1 & age_e1!=0, 			p(1) h(24)	covs(dummy*)
	est sto m1
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)
	
rdrobust voted age_e2 if  england==1 & age_e2!=0,		 	p(1) h(24)	covs(dummy*)
	est sto m2
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)
	
rdrobust voted age_e3 if  england==1 & age_e3!=0,		 	p(1) h(24)	covs(dummy*)
	est sto m3
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)
	
rdrobust voted rel_age if england==1 & rel_age!=0,  		p(1)  h(24) covs(dummy*)
	est sto mpooled
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)
	
estout m* using "Tables/a_tb3.tex", ///
style(tex) cells (b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
starlevels( * 0.1 ** 0.05 *** 0.01)  varlabels(RD_Estimate "\hline \\ \\ RD estimate")	  ///
stats(eff_obs, fmt(%9.0gc) labels("\hline N"))    mlabels(none	) ///
collabels(none) eql(none) notype label replace	
